const express = require('express');
const { body, param } = require('express-validator');
const LikeController = require('../../controllers/LikeController');
const { authenticateJWT, authorizeAdmin } = require('../../middleware/auth');

const router = express.Router();

// 需要认证的接口
// 视频点赞/取消点赞
router.post('/video/:videoId', authenticateJWT, [
  param('videoId').isNumeric().withMessage('视频ID必须是数字')
], LikeController.toggleVideoLike);


// 检查用户是否点赞了视频
router.get('/video/:videoId/check', authenticateJWT, [
  param('videoId').isNumeric().withMessage('视频ID必须是数字')
], LikeController.checkVideoLiked);

// 批量检查视频点赞状态
router.post('/video/batch/check', authenticateJWT, [
  body('videoIds').isArray().withMessage('videoIds必须是数组').notEmpty().withMessage('videoIds不能为空'),
  body('videoIds.*').isNumeric().withMessage('视频ID必须是数字')
], LikeController.batchCheckVideoLiked);

// 管理员接口
// 获取视频的点赞列表
router.get('/video/:videoId/list', authenticateJWT, authorizeAdmin, [
  param('videoId').isNumeric().withMessage('视频ID必须是数字')
], LikeController.getVideoLikes);

module.exports = router;